import { LiveType } from '@/model/home/types';
import { Live } from '@/model/live/Live';
import { useInjectable } from '@/unit/hooks/use-di';
import { RedirectTo } from '@/unit/navigate-to';
import {
  observable,
  action,
  makeObservable,
  computed,
} from 'mobx';
import { singleton } from 'tsyringe';

@singleton()
export class Tabs {
  @observable public activekey = 0;

  @action public setState = (state: number) => {
    // const live = useInjectable(Live);
    switch (state) {
      case 0:
        RedirectTo('home');
        break;
      case 2:
        RedirectTo('mine');
        break;
      case 1:
        RedirectTo('live-add');
        break;
    }
    this.activekey = state;
  };

  @action public setActive = (state: number) => {
    this.activekey = state;
  };

  @action public init = () => {
    const hash = window.location.hash;
    console.log(hash);
    switch (hash) {
      case '#/pages/home/home':
        this.setState(0);
        break;
      case '#/pages/mine/mine':
        this.setState(2);
        break;
    }
  };

  @computed get getActive(): number {
    return this.activekey;
  }

  constructor() {
    makeObservable(this);
  }
}
